<?php
namespace app\admin\controller;
use think\Controller;
use think\Db;
use think\Request;
class Common extends Controller{

	public function _initialize()
    {

    	$request = Request::instance();

		$url =  strtolower($request->module()."/".$request->controller().'/'.$request->action());


		if(!$this->check_auth(session('admin_id'),$url)){
			echo '你还没有权限,请联系管理开通';exit;
		}
    }

    public function check_auth($admin_id,$url)
    {
    	$rules =  Db::name('auth_admin_role')
		->alias('t1')
		->field('t2.rule')
		->join('auth_role t2','t1.role_id = t2.role_id')
		->where('t1.admin_id',$admin_id)
		->select();

		if(!$rules)
			return false;

		$ruleList = [];

		foreach ($rules as $role) {
			$ruleList = array_merge($ruleList,explode(',', $role['rule']));
		}

		$ruleList = array_unique($ruleList);


		$rules = Db::name('auth_rule')->where('rule_id','in',$ruleList)->column('title');


		if(in_array($url,$rules)){
			return true;
		}else{
			return false;
		}
    }
}



// mysql 

// yii

// ci

// larver

// linux

// 微信 小程序 

// 工作
